package std.bank;

import java.io.IOException;
import java.rmi.RemoteException;
import java.util.HashMap;

public class BankRPC implements Bank
{
	ClientStub client;
	HashMap<String, Account> accountMap = new HashMap();
	
	public BankRPC()
	{
		try
		{
			Object[] parameterValues = {};
			Class<?>[] parameterTypes = {};
			client = new ClientStub(parameterTypes, parameterValues);
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public Account getAccount(String name) throws RemoteException 
	{	
		Account newAccount;
		if(accountMap.values().contains(name))
		{
			return accountMap.get(name);
		}
		else
		{
			try
			{
				newAccount = new AccountRPC(name, 0);
				accountMap.put(name, newAccount);
				return newAccount;
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}
		}
		return null;
	}
	
}
